package com.ruicar.afs.cloud.apply.admin.auth.util;

import com.ruicar.afs.cloud.common.core.security.service.AfsUser;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.modules.apply.enums.RoleEnum;
import com.ruicar.afs.cloud.common.modules.apply.enums.UserExtInfoKeyEnum;

import java.util.List;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description:
 */
public class DataAccessUtil {

    /**
     * 判断当前登陆人是否是admin超级管理员用户，如果是admin用户则返回false，不是admin用户返回true
     *
     * @return
     */
    public static Boolean isAdmin() {
        AfsUser user = SecurityUtils.getUser();
        List<String> roleCodeList = user.getRoleCodeList();
        return !roleCodeList.contains(RoleEnum.ROLE_ADMIN.name());
    }

    /**
     * 获取当前登录人的channelId
     *
     * @return
     */
    public static Long getChannelId() {
        AfsUser user = SecurityUtils.getUser();
        return Long.valueOf(String.valueOf(user.getUserExtInfo().get(UserExtInfoKeyEnum.channelId.name())));
    }
}
